package se.gala.core;

import se.gala.core.abstracts.AbstractBet;
import se.gala.core.abstracts.StakeTypeChangeable;
import se.gala.core.abstracts.Wagerable;
import se.gala.core.abstracts.Wagering;

public abstract class FixedOddsBet extends AbstractBet implements StakeTypeChangeable {

	protected Wagerable stakeType;
	protected Wagering betValue;
	
	public FixedOddsBet(int stakeAmount, Wagerable stakeType, Wagering betValue) {
		super(stakeAmount);
		this.stakeType = stakeType;
		this.betValue = betValue;
		
		try {
			checkEventTypeAndValueIntegrity();
		} catch (IncompatibleStakeTypeException e) {
			e.printStackTrace();
		}
	}
	
	public Wagerable getStakeType() {
		return stakeType;
	}
	
	public Wagering getBetValue() {
		return betValue;
	}
	
	public int calculateWinningAmount() {
		int winAmount = Math.round(getStakeAmount() * stakeType.getPayout());
//		log("winAmount: " + winAmount + " >> of " + getStakeAmount() + " * " + stakeType.getPayout());
		if (winsInitialStake()) {
			winAmount += getStakeAmount();
		}
		return winAmount;
	}

	@Override
	public void changeStakeType(Wagerable stakeType) {
		this.stakeType = stakeType;
	}
	
	/**
	 * Determines if the stake should be included in the won amount or not.
	 * @return
	 */
	abstract protected boolean winsInitialStake();
	
	abstract protected void checkEventTypeAndValueIntegrity() throws IncompatibleStakeTypeException;
}
